// ServerSocket.h: interface for the ServerSocket class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_SERVERSOCKET_H__23FDFD21_6E9D_4C40_81B2_87ABEE94E6C1__INCLUDED_)
#define AFX_SERVERSOCKET_H__23FDFD21_6E9D_4C40_81B2_87ABEE94E6C1__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "../thread.h"
#include "../types.h"
#include "CNode.h"
#include "ClientReceiver.h"
#include "../codigoServerCliente.h"
#include "ServerOutputStream.h"
#include <fstream>
#include <iostream>
#include <string>
#include "..\figuras\circulo.h"
#include "..\figuras\triangulo.h"
#include "..\figuras\rectangulo.h"
#include "..\figuras\segmento.h"

class ServerSocket : public thread{
public:
	ServerSocket(MapObservers& mapObservers,unsigned int puerto=5555, unsigned int max=2);
	
	ServerOutputStream& getOuputStream(); 
	
	virtual ~ServerSocket();

	virtual void run();

	bool allConnected();

	void sincronizarTexturas(listaTexturas* lista);
	void sincronizarNivel(listaFiguras* lista);
	void sendStartMessage();
	void sendEndMessage(int puntaje1,int puntaje2);
	void closeAllConnections();
	bool ServerSocket::checkAllConnected();

private:
	MapObservers mapObservers;
	VectorClientReceiver receivers;
	VectorCNode clientes;
	ServerOutputStream outputStream;
	unsigned int maxClients;
	unsigned int puerto;
	SOCKET csocket;
	Mutex mapMutex;
	void setupServer();

	int sumarTamTextura(figura* fig);

	int preprocesamientoTamLista(listaFiguras* lista);

	

};

#endif // !defined(AFX_SERVERSOCKET_H__23FDFD21_6E9D_4C40_81B2_87ABEE94E6C1__INCLUDED_)
